//k1 edit 21.12.18

private ["_center","_rotation","_obj","_pos","_parkedVehicleClasses"];

_center               = [_this, 0] call bis_fnc_param;
_rotation             = [_this, 1] call bis_fnc_param;
_staticWeaponClasses  = [_this, 2, []] call bis_fnc_param;
_parkedVehicleClasses = [_this, 3, []] call bis_fnc_param;
_parkedArmorClasses   = [_this, 4, []] call bis_fnc_param;
_staticAAClasses      = [_this, 5, []] call bis_fnc_param;

if (isNil "A3E_MotorPoolMarkerNumber") then {
    A3E_MotorPoolMarkerNumber = 0;
} else {
    A3E_MotorPoolMarkerNumber = A3E_MotorPoolMarkerNumber + 1;
};
_mNumber = A3E_MotorPoolMarkerNumber;

_fnc_createObject = {
    params["_className","_centerPos","_relativePos","_rotateDir","_relativeDir"];
    private["_object", "_realPos", "_realDir"];

    _fnc_rotatePos = {
        private ["_centerPos", "_pos", "_dir"];
        private ["_px", "_py", "_mpx", "_mpy", "_ma", "_rpx", "_rpy"];
        _centerPos = _this select 0;
        _pos = _this select 1;
        _dir = _this select 2;
        _px = _pos select 0;
        _py = _pos select 1;
        _mpx = _centerPos select 0;
        _mpy = _centerPos select 1;
        _ma = _dir;
        _rpx = ( (_px - _mpx) * cos(_ma) ) + ( (_py - _mpy) * sin(_ma) ) + _mpx;
        _rpy = (-(_px - _mpx) * sin(_ma) ) + ( (_py - _mpy) * cos(_ma) ) + _mpy;
        [_rpx, _rpy, (_pos select 2)];
    };

    _realPos = ([_centerPos, [(_centerPos select 0) + (_relativePos select 0), (_centerPos select 1) + (_relativePos select 1),(_relativePos select 2)], _rotateDir] call _fnc_rotatePos);
    _object = createVehicle [_className, _realPos, [], 0, "CAN_COLLIDE"];
    _object setdir (_relativeDir + _rotateDir);
    _object setPosATL _realPos;
    _object
};

_obj = objNull;
_obj = ["Land_Cargo_House_V1_F",_center,[-11.6426,-5.05859,0],_rotation,270] call _fnc_createObject;
_obj = ["Land_Cargo_House_V1_F",_center,[-11.5317,-13.3633,0],_rotation,270] call _fnc_createObject;
_obj = ["Land_BagBunker_Tower_F",_center,[-6.75684,-22.3257,0],_rotation,0] call _fnc_createObject;
_obj = ["Land_HBarrierWall6_F",_center,[-18.1318,-15.3257,0],_rotation,270] call _fnc_createObject;
_obj = ["Land_HBarrierWall6_F",_center,[-18.1318,-7.07568,0],_rotation,270] call _fnc_createObject;
_obj = ["Land_HBarrierWall6_F",_center,[-7.88184,-18.2007,0],_rotation,180] call _fnc_createObject;
_obj = ["Land_HBarrierWall6_F",_center,[-16.2568,-18.3257,0],_rotation,180] call _fnc_createObject;
_obj = ["Land_HBarrierWall6_F",_center,[-18.3818,17.9243,0],_rotation,270] call _fnc_createObject;
_obj = ["Land_HBarrierWall6_F",_center,[-16.5068,21.2993,0],_rotation,0] call _fnc_createObject;
_obj = ["Land_HBarrierWall6_F",_center,[-18.2568,1.29932,0],_rotation,270] call _fnc_createObject;
_obj = ["Land_HBarrierWall6_F",_center,[-18.2568,9.54932,0],_rotation,270] call _fnc_createObject;
_obj = ["Land_HBarrierWall6_F",_center,[-8.25684,21.5493,0],_rotation,0] call _fnc_createObject;
_obj = ["Land_HBarrierWall6_F",_center,[18.6182,-14.4507,0],_rotation,90] call _fnc_createObject;
_obj = ["Land_HBarrierWall6_F",_center,[8.49316,-17.9507,0],_rotation,180] call _fnc_createObject;
_obj = ["Land_HBarrierWall6_F",_center,[16.7432,-17.7007,0],_rotation,180] call _fnc_createObject;
_obj = ["Land_HBarrierWall6_F",_center,[18.4932,-6.07568,0],_rotation,90] call _fnc_createObject;
_obj = ["Land_HBarrierWall6_F",_center,[16.4932,21.9243,0],_rotation,0] call _fnc_createObject;
_obj = ["Land_HBarrierWall6_F",_center,[18.3682,18.7993,0],_rotation,90] call _fnc_createObject;
_obj = ["Land_HBarrierWall6_F",_center,[18.3682,10.5493,0],_rotation,90] call _fnc_createObject;
_obj = ["Land_HBarrierWall6_F",_center,[-0.0068,21.6743,0],_rotation,0] call _fnc_createObject;
_obj = ["Land_HBarrierWall6_F",_center,[8.24316,21.7993,0],_rotation,0] call _fnc_createObject;
_obj = ["Land_HBarrierWall6_F",_center,[18.4932,2.17432,0],_rotation,90] call _fnc_createObject;
_obj = ["Land_Razorwire_F",_center,[-21.5068,-18.4507,0],_rotation,270] call _fnc_createObject;
_obj = ["Land_Razorwire_F",_center,[-15.8818,-21.8257,0],_rotation,0] call _fnc_createObject;
_obj = ["Land_Razorwire_F",_center,[-21.5068,-10.3257,0],_rotation,270] call _fnc_createObject;
_obj = ["Land_Razorwire_F",_center,[-21.6318,6.04932,0],_rotation,270] call _fnc_createObject;
_obj = ["Land_Razorwire_F",_center,[-21.7568,14.1743,0],_rotation,270] call _fnc_createObject;
_obj = ["Land_Razorwire_F",_center,[-16.6318,25.2993,0],_rotation,180] call _fnc_createObject;
_obj = ["Land_Razorwire_F",_center,[-21.7568,22.2993,0],_rotation,270] call _fnc_createObject;
_obj = ["Land_Razorwire_F",_center,[-21.6318,-2.07568,0],_rotation,270] call _fnc_createObject;
_obj = ["Land_Razorwire_F",_center,[-8.50684,25.2993,0],_rotation,180] call _fnc_createObject;
_obj = ["Land_Razorwire_F",_center,[16.6182,-21.2007,0],_rotation,0] call _fnc_createObject;
_obj = ["Land_Razorwire_F",_center,[21.8682,-17.8257,0],_rotation,270] call _fnc_createObject;
_obj = ["Land_Razorwire_F",_center,[21.8682,-9.70068,0],_rotation,270] call _fnc_createObject;
_obj = ["Land_Razorwire_F",_center,[7.74316,25.4243,0],_rotation,180] call _fnc_createObject;
_obj = ["Land_Razorwire_F",_center,[21.7432,5.42432,0],_rotation,270] call _fnc_createObject;
_obj = ["Land_Razorwire_F",_center,[15.9932,25.4243,0],_rotation,180] call _fnc_createObject;
_obj = ["Land_Razorwire_F",_center,[-0.381836,25.4243,0],_rotation,180] call _fnc_createObject;
_obj = ["Land_Razorwire_F",_center,[21.7432,22.05,0],_rotation,270] call _fnc_createObject;
_obj = ["Land_Razorwire_F",_center,[21.7432,14,0],_rotation,270] call _fnc_createObject;
_obj = ["Land_Razorwire_F",_center,[21.7432,-2.7,0],_rotation,270] call _fnc_createObject;
_obj = ["Land_HBarrierTower_F",_center,[-16.1318,18.9243,0],_rotation,135] call _fnc_createObject;
_obj = ["Land_HBarrierTower_F",_center,[15.7432,19.5493,0],_rotation,225] call _fnc_createObject;
_obj = ["Land_BagBunker_Small_F",_center,[-17.2568,19.67,4.21],_rotation,135] call _fnc_createObject;
_obj = ["Land_BagBunker_Small_F",_center,[16.243,19.924,4.21],_rotation,225] call _fnc_createObject;
_obj = ["Land_Cargo_HQ_V1_F",_center,[11.245,-8.22,0],_rotation,90] call _fnc_createObject;
_obj = ["Land_BarGate_F",_center,[0.743,-29.7,0],_rotation,180] call _fnc_createObject;
_obj = ["Land_BagBunker_Tower_F",_center,[7.243,-22.0757,0],_rotation,0] call _fnc_createObject;
_obj = ["Land_TentHangar_V1_F",_center,[-1,12.25,0],_rotation,180] call _fnc_createObject; //

_obj = ["Box_East_WpsSpecial_F",_center,[-14.68,-12.95,1],_rotation,0] call _fnc_createObject;
_obj allowDamage false;
_obj = ["Box_East_WpsSpecial_F",_center,[-14.75,-5,1],_rotation,0] call _fnc_createObject;
_obj allowDamage false;
_obj = ["Box_East_Ammo_F",_center,[16.75,-13,1],_rotation,180] call _fnc_createObject;
_obj allowDamage false;
_obj = ["Box_East_WpsLaunch_F",_center,[16.75,-11.5,1],_rotation,180] call _fnc_createObject;
_obj allowDamage false;
_obj = ["Box_East_Wps_F",_center,[16.75,-14.5,1],_rotation,180] call _fnc_createObject;
_obj allowDamage false;

//Statics
_MGGMH = a3e_arr_Escape_SWC_MG_H + a3e_arr_Escape_SWC_GM_H;
_gun = selectRandom _MGGMH;
_obj = [_gun,_center,[-7.00684,-24.0757,0],_rotation,180] call _fnc_createObject;
Escape_allStatics pushback _obj;
Escape_all_assets pushback _obj;
_obj setVariable ["Escape_assets_control", true, true];
_gun = selectRandom _MGGMH;
_obj = [_gun,_center,[-7.00684,-24.2007,2.77],_rotation,180] call _fnc_createObject;
Escape_allStatics pushback _obj;
Escape_all_assets pushback _obj;
_obj setVariable ["Escape_assets_control", true, true];
_gun = selectRandom _MGGMH;
_obj = [_gun,_center,[-17.5,20.232,2.27],_rotation,315] call _fnc_createObject;
Escape_allStatics pushback _obj;
Escape_all_assets pushback _obj;
_obj setVariable ["Escape_assets_control", true, true];
_gun = selectRandom _MGGMH;
_obj = [_gun,_center,[-17.52,19.91,4.2],_rotation,315] call _fnc_createObject;
Escape_allStatics pushback _obj;
Escape_all_assets pushback _obj;
_obj setVariable ["Escape_assets_control", true, true];
_gun = selectRandom _MGGMH;
_obj = [_gun,_center,[7.3,-23.64,0],_rotation,180] call _fnc_createObject;
Escape_allStatics pushback _obj;
Escape_all_assets pushback _obj;
_obj setVariable ["Escape_assets_control", true, true];
_gun = selectRandom _MGGMH;
_obj = [_gun,_center,[6.2,-7.11,3.11],_rotation,270] call _fnc_createObject;
Escape_allStatics pushback _obj;
Escape_all_assets pushback _obj;
_obj setVariable ["Escape_assets_control", true, true];
_gun = selectRandom _MGGMH;
_obj = [_gun,_center,[16.2646,-14.01,3.1],_rotation,135] call _fnc_createObject;
Escape_allStatics pushback _obj;
Escape_all_assets pushback _obj;
_obj setVariable ["Escape_assets_control", true, true];
_gun = selectRandom _MGGMH;
_obj = [_gun,_center,[7.12,-24.0757,2.77],_rotation,180] call _fnc_createObject;
Escape_allStatics pushback _obj;
Escape_all_assets pushback _obj;
_obj setVariable ["Escape_assets_control", true, true];
_gun = selectRandom _MGGMH;
_obj = [_gun,_center,[14,-5.5,3.1],_rotation,45] call _fnc_createObject;
Escape_allStatics pushback _obj;
Escape_all_assets pushback _obj;
_obj setVariable ["Escape_assets_control", true, true];
_gun = selectRandom _MGGMH;
_obj = [_gun,_center,[17.065,20.9,2.3],_rotation,45] call _fnc_createObject;
Escape_allStatics pushback _obj;
Escape_all_assets pushback _obj;
_obj setVariable ["Escape_assets_control", true, true];
_gun = selectRandom _MGGMH;
_obj = [_gun,_center,[16.4717,20.0237,4.2],_rotation,45] call _fnc_createObject;
Escape_allStatics pushback _obj;
Escape_all_assets pushback _obj;
_obj setVariable ["Escape_assets_control", true, true];
_gun = selectRandom _MGGMH;

_MGGMA = a3e_arr_Escape_SWC_MG_A + a3e_arr_Escape_SWC_GM_A;
_gun = selectRandom _MGGMA;
_obj = [_gun,_center,[-6.7685,-20.446,2.86],_rotation,270] call _fnc_createObject;
Escape_allStatics pushback _obj;
_gun = selectRandom _MGGMA;
_obj = [_gun,_center,[7.2153,-20.221,2.86],_rotation,90] call _fnc_createObject;
Escape_allStatics pushback _obj;

_gun = selectRandom a3e_arr_Escape_SWC_launcher_AT;
_obj = [_gun,_center,[-6.79102,-23.972,4.91],_rotation,225] call _fnc_createObject;
[_obj,A3E_VAR_Side_Opfor] spawn A3E_fnc_AddStaticGunner;
Escape_all_assets pushback _obj;
_obj setVariable ["Escape_assets_control", true, true];
_gun = selectRandom a3e_arr_Escape_SWC_launcher_AT;
_obj = [_gun,_center,[-17.4907,19.695,6.21],_rotation,315] call _fnc_createObject;
[_obj,A3E_VAR_Side_Opfor] spawn A3E_fnc_AddStaticGunner;
Escape_all_assets pushback _obj;
_obj setVariable ["Escape_assets_control", true, true];
_gun = selectRandom a3e_arr_Escape_SWC_launcher_AT;
_obj = [_gun,_center,[6.99316,-23.7,4.91],_rotation,135] call _fnc_createObject;
[_obj,A3E_VAR_Side_Opfor] spawn A3E_fnc_AddStaticGunner;
Escape_all_assets pushback _obj;
_obj setVariable ["Escape_assets_control", true, true];
_gun = selectRandom a3e_arr_Escape_SWC_launcher_AT;
_obj = [_gun,_center,[16.231,20.255,6.21],_rotation,45] call _fnc_createObject;
[_obj,A3E_VAR_Side_Opfor] spawn A3E_fnc_AddStaticGunner;
Escape_all_assets pushback _obj;
_obj setVariable ["Escape_assets_control", true, true];

if (productVersion select 2 < 200) then [{
	_box = ["Box_NATO_AmmoVeh_F",_center,[3.75,16.25,0],_rotation,270] call _fnc_createObject; //
	_box allowDamage false;
	clearWeaponCargoGlobal _box;
	clearMagazineCargoGlobal _box;
	clearItemCargoGlobal _box;
	clearBackpackCargoGlobal _box;
	_weapons = [];
	_weaponMagazines = [];
	_c = count a3e_arr_AmmoDepotVehicle - 1;
	for "_i" from 0 to _c do {
		private ["_handGunItem", "_weaponClassName", "_probabilityOfPrecence", "_minCount", "_maxCount", "_magazines", "_magazinesPerWeapon"];
        _handGunItem = a3e_arr_AmmoDepotVehicle select _i;
        _weaponClassName = _handGunItem select 0;
        _probabilityOfPrecence = _handGunItem select 1;
        _minCount = _handGunItem select 2;
        _maxCount = _handGunItem select 3;
        _magazines = _handGunItem select 4;
        _magazinesPerWeapon = _handGunItem select 5;
        if (random 100 <= _probabilityOfPrecence) then {
            _weaponCount = floor (_minCount + random (_maxCount - _minCount));
            _weapons pushBack [_weaponClassName, _weaponCount];
			_c = count _magazines - 1;
            for "_j" from 0 to _c do {
                _weaponMagazines pushBack [_magazines select _j, _weaponCount * _magazinesPerWeapon];
            };
        };
    };
	_items = [];
	_c = count a3e_arr_AmmoDepotVehicleItems - 1;
	for "_i" from 0 to _c do {
		private ["_item", "_itemClassName", "_probabilityOfPrecence", "_minCount", "_maxCount"];
		_item = a3e_arr_AmmoDepotVehicleItems select _i;
        _itemClassName = _item select 0;
        _probabilityOfPrecence = _item select 1;
        _minCount = _item select 2;
        _maxCount = _item select 3;
        if (random 100 <= _probabilityOfPrecence) then {
            _itemCount = floor (_minCount + random (_maxCount - _minCount));
            _items pushback [_itemClassName, _itemCount];
        };
    };
	if (count _weapons > 0 || {count _weaponMagazines > 0} || {count _items > 0}) then {
		{_box addWeaponCargoGlobal _x} forEach _weapons; 
		{_box addMagazineCargoGlobal _x} forEach _weaponMagazines;
		{_box addBackpackCargoGlobal [_x,4]} forEach a3e_arr_AmmoDepotVehicleBackpacks;
		{_box addItemCargoGlobal _x} forEach _items;
	};
},{
	_obj = ["Land_RepairDepot_01_green_F",_center,[3.75,16.25,0],_rotation,270] call _fnc_createObject; //
}];

//veh
_vehicle = selectRandom a3e_arr_ComCenDefence_heavyArmorClasses;
_obj = [_vehicle,_center,[-5.75,7.26,0],_rotation,180] call _fnc_createObject; //
_obj setfuel (random 1);
_obj setDamage (random [0,.2,.5]);
Escape_all_assets pushback _obj;
_obj setVariable ["Escape_assets_control", true, true];
_parkedVehicleClasses append ["C_Heli_Light_01_civil_F","B_Heli_Light_01_F","I_Heli_light_03_unarmed_F"];
_vehicle = selectRandom _parkedVehicleClasses;
_obj = [_vehicle,_center,[3.5,6.75,0],_rotation,180] call _fnc_createObject; //
_obj setfuel (random 1);
_obj setDamage (random [0,.2,.5]);
Escape_all_assets pushback _obj;
_obj setVariable ["Escape_assets_control", true, true];

Escape_campType_arr pushback [_center,"载具点","Jade"];
publicVariable "Escape_campType_arr";

["A3E_MotorPoolMapMarker" + str _mNumber,_center,"o_service"] call A3E_fnc_createLocationMarker;

_marker = createMarkerLocal ["A3E_MotorPoolPatrolMarker" + str _mNumber, _center];
_marker setMarkerShapeLocal "RECTANGLE";
_marker setMarkerAlphaLocal 0;
_marker setMarkerSizeLocal [40,38];


